package com.ziyun.erp.web.modules.business.controller;

import com.ziyun.erp.modules.business.entity.BusinessMessageEntity;
import com.ziyun.erp.modules.business.service.BusinessMessagePeopleService;
import com.ziyun.erp.modules.business.service.BusinessMessageService;
import io.renren.common.utils.R;
import io.renren.common.validator.ValidatorUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;


/**
 * 营销短信表
 *
 * @author jiangli
 * @email
 * @date 2018-08-21 14:37:06
 */
@RestController
@RequestMapping("business/businessmessage")
public class BusinessMessageController {
    @Autowired
    private BusinessMessageService businessMessageService;
    @Autowired
    private BusinessMessagePeopleService businessMessagePeopleService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("business:businessmessage:list")
    public R list(@RequestParam Map<String, Object> params) {
        return businessMessageService.list(params);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("business:businessmessage:info")
    public R info(@PathVariable("id") Integer id) {
        BusinessMessageEntity businessMessage = businessMessageService.selectById(id);

        return R.ok().put("businessMessage", businessMessage);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("business:businessmessage:save")
    public R save(BusinessMessageEntity businessMessage, String phones) {
        businessMessageService.insertOne(businessMessage, phones);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("business:businessmessage:update")
    public R update(BusinessMessageEntity businessMessage) {
        ValidatorUtils.validateEntity(businessMessage);
        businessMessageService.updateById(businessMessage);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("business:businessmessage:delete")
    public R delete(@RequestBody Integer[] ids) {
        businessMessageService.deleteBatchIds(Arrays.asList(ids));

        return R.ok();
    }


}
